package com.wc.AlgoOJ_train.train2_DP训练.c3.DP0103;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/1/12 22:02
 * @description 多重背包1的优化 空间
 * 01背包的扩展，所以也需要从大到小
 */
public class Answer {
    static int maxN = 100 + 7;
    static int[] dp = new int[maxN];
    static int n, m;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int w, v, l;
            w = sc.nextInt();
            v = sc.nextInt();
            l = sc.nextInt();
            for (int j = m; j >= w; j--) {
                for (int k = 1; k <= l && k * w <= j; k++) {
                    dp[j] = Math.max(dp[j], dp[j - k * w] + k * v);
                }
            }
        }
        System.out.println(dp[m]);
    }
}
